// 引入评论集合构造函数
const Comment = require('../../../model/comment')
//引入mongoose-sex-page模块用于分页
const pagination = require('mongoose-sex-page');

module.exports = async(req, res) => {
  // 获取用户id参数
  const { id } = req.params
  // 获取分页数据
  const { pagenum, pagesize } = req.query
  // 查找当前用户id的0层评论
  const comments = await pagination(Comment).find({ level: 0, user: id }).populate([
    { path: 'user'},
    { path: 'response', populate: {path: 'user'}}
  ]).page(pagenum).size(pagesize).display(5).exec()
  // 返回结果
  res.send({
    comments,
    meta: {
      msg: '获取当前id的0层评论数据成功',
      status: 200
    }
  })
}